import resources.Constants;
import registnet.dao.SystemPropertiesPeer;
import registnet.dao.SystemProperties;
import registnet.dao.SystemLogPeer;

SystemPropertiesPeer spp = new SystemPropertiesPeer();
SystemProperties sp = spp.getSystemProperties();

String _year1Value;
String _year2Value;
String _semesterValue;

try{
	_semesterValue = Constants.MAP_SEMESTER_VALUE.get(sp.getSemester());
	if (sp.getSemester() != 3){
		_year1Value = "" + sp.getAcademicYear();
		_year2Value = "" + (sp.getAcademicYear() + 1);
	}
	else{
		_year2Value = "" + sp.getAcademicYear();
		_year1Value = "" + (sp.getAcademicYear() - 1);
	}
}catch(Exception e){}


/* [start]	automatically updates the 'to' value of academic year based on the
			current 'from' value of the academic year */
private void updateAY(){
	try{
		year2.value = (Integer.parseInt(event.value) + 1).toString();
	}catch(Exception e) {year1.value = null; year2.value = null;}
}
/* [end] */


void submit(){
	int yearValue;
	int semesterValue = Constants.MAP_SEMESTER_KEY.get(semester.getText());
	if (!semester.getText().equals(Constants.SUMMER)){
		yearValue = Integer.parseInt(year1.value);
	}
	else{
		yearValue = Integer.parseInt(year2.value);
	}
	try{
		spp.updateSystemProperties(sp.getSystemPropertiesId(), yearValue, semesterValue);
	}catch(Exception e){
		spp.createNewSystemProperties(yearValue, semesterValue);
	}
	SystemLogPeer.createNewSystemLog("Year and Semester was updated to "+semester.getText()+" "+yearValue+"-"+(yearValue+1), "registnet", "Administrator");
	alert("Edit Year/Semester successful");
	
}